﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Language" content="UTF-8" />
<link href="../../../style.css" rel="stylesheet" type="text/css" />
<title>信用卡无卡支付-消费</title>
</head>
<body style="text-align:center;">
<?php

//接口版本号
$version = '1.0';
//交易类型编码
$txnType = 'PUR';
//消息状态
$interactiveStatus = 'TR1';
//信用卡卡号
$cardNo = '5528010000000001';
//卡效期
$expiredDate = '0911';
//安全校验值  卡背面后三位
$cvv2 = '111';
//交易金额
$amount = '1';
//商户编号  由快钱公司分配给商户的 15位唯一标识号。 
$merchantId = '812330945110001';
//结算商户编号
$settleMerchantId = '';
//终端编号
$terminalId = '33090301';
//客户姓名
$cardHolderName = '个人';
//客户身份证号
$cardHolderId = '11212';
//证件类型  持卡客户的证件类型
$idType = '0';
//商户端交易时间
$entryTime = date('YmdHis');
//外部检索参考号  用于商户自定义标识一笔交易
$externalRefNumber = date('YmdHis');
//客户号
$customerId = date('YmdHis');
//储值卡密码
$pin = '';
//持卡人国籍
$issuerCountry = '';
//交易发生地点类型
$siteType = '';
//交易发生地点编号
$siteID = '';
//储值卡动态密码
$dynPin = '';
//储值卡序列号
$serialNo = '';
//特殊交易标志
$spFlag = '';
//扩展字段
$ext = '';
//扩展字段 1
$ext1 = '';
//扩展数据键
$key = 'phone';
//扩展数据值
$value = '15850693123';
//tr3回调地址  接收快钱TR3报文的地址
$tr3Url = 'http://219.233.173.50:8804/pur_vpos_tr3.aspx';

?>
<h2>消费交易提交到快钱</h2>
<font color="#ff0000">（该页面仅做参考）</font>
<form method=post action="" name="">
	<table cellpadding="0" width="610px" border="1" style="border-collapse: collapse" bordercolor="green" align="center">
		<tr>
			<td>接口版本号(version)<span class="">*</span></td>
			<td><?php echo $version; ?></td>
		</tr>
		<tr>
			<td>交易类型(txnType)<span class="">*</span></td>
			<td><?php echo $txnType; ?></td>
		</tr>
		<tr>
			<td>消息状态(interactiveStatus)<span class="">*</span></td>
			<td><?php echo $interactiveStatus; ?></td>
		</tr>
		<tr>
			<td>卡号(cardNo)<span class="">*</span></td>
			<td><?php echo $cardNo; ?></td>
		</tr>
		<tr>
			<td>卡效期(expiredDate)<span class="">*</span></td>
			<td><?php echo $expiredDate; ?></td>
		</tr>
		<tr>
			<td>安全校验值(cvv2)<span class="">*</span></td>
			<td><?php echo $cvv2; ?></td>
		</tr>
		<tr>
			<td>交易金额(amount)<span class="">*</span></td>
			<td><?php echo $amount; ?></td>
		</tr>
		<tr>
			<td>商户编号(merchantId)<span class="">*</span></td>
			<td><?php echo $merchantId; ?></td>
		</tr>
		<tr>
			<td>终端编号(terminalId)<span class="">*</span></td>
			<td><?php echo $terminalId; ?></td>
		</tr>
		<tr>
			<td>证件类型(idType)<span class=""></span></td>
			<td><?php echo $idType; ?></td>
		</tr>
		<tr>
			<td>客户身份证号(cardHolderId)<span class=""></span></td>
			<td><?php echo $cardHolderId; ?></td>
		</tr>
		<tr>
			<td>商户端交易时间(entryTime)<span class="">*</span></td>
			<td><?php echo $entryTime; ?></td>
		</tr>
		<tr>
			<td>外部跟踪编号(externalRefNumber)<span class="">*</span></td>
			<td><?php echo $externalRefNumber; ?></td>
		</tr>
		<tr>
			<td>扩展数据键(key)<span class=""></span></td>
			<td><?php echo $key; ?></td>
		</tr>
		<tr>
			<td>扩展数据值(value)<span class=""></span></td>
			<td><?php echo $value; ?></td>
		</tr>
		<tr>
			<td>tr3 回调地址  (tr3Url)<span class=""></span></td>
			<td><?php echo $tr3Url; ?></td>
		</tr>
		
		<tr>
			<td colspan="2" style="text-align: center">
			<input type="submit" value="消费 提交" name="go_search" style="font-size:x-large;height:34px;width:177px"/>
			</td>
		</tr>
	</table>	
</form>
</body>
</html>

<?PHP

if($_POST[go_search]){

function kq_ck_null($kq_va,$kq_na)
	{
		if($kq_va == ""){$kq_va="";
		}else
			{return '<'.$kq_na.'>'.$kq_va.'</'.$kq_na.'>';
			}
			}

$settleMerchantId=kq_ck_null($settleMerchantId,'settleMerchantId');
$cardHolderName  =kq_ck_null($cardHolderName,'cardHolderName');
$settleMerchantId=kq_ck_null($settleMerchantId,'settleMerchantId');
$cardHolderName  =kq_ck_null($cardHolderName,'cardHolderName');
$cardHolderId    =kq_ck_null($cardHolderId,'cardHolderId');
$idType          =kq_ck_null($idType,'idType');
$customerId      =kq_ck_null($customerId,'customerId');
$pin             =kq_ck_null($pin,'pin');
$issuerCountry   =kq_ck_null($issuerCountry,'issuerCountry');
$siteType        =kq_ck_null($siteType,'siteType');
$siteID          =kq_ck_null($siteID,'siteID');
$dynPin          =kq_ck_null($dynPin,'dynPin');
$serialNo        =kq_ck_null($serialNo,'serialNo');
$spFlag          =kq_ck_null($spFlag,'spFlag');
$ext             =kq_ck_null($ext,'ext');
$ext1            =kq_ck_null($ext1,'ext1');
$key             =kq_ck_null($key,'key');
$value           =kq_ck_null($value,'value');
$tr3Url          =kq_ck_null($tr3Url,'tr3Url');

$reqXml = '<?xml version="1.0" encoding="UTF-8"?><MasMessage xmlns="http://www.99bill.com/mas_cnp_merchant_interface"><version>'.$version.'</version><TxnMsgContent><txnType>'.$txnType.'</txnType><interactiveStatus>'.$interactiveStatus.'</interactiveStatus><cardNo>'.$cardNo.'</cardNo><expiredDate>'.$expiredDate.'</expiredDate><cvv2>'.$cvv2.'</cvv2><amount>'.$amount.'</amount><merchantId>'.$merchantId.'</merchantId>'.$settleMerchantId.'<terminalId>'.$terminalId.'</terminalId>'.$cardHolderName.$cardHolderId.$idType.'<entryTime>'.$entryTime.'</entryTime><externalRefNumber>'.$externalRefNumber.'</externalRefNumber>'.$customerId.$pin.$issuerCountry.$siteType.$siteID.$dynPin.$serialNo.$spFlag.$ext.$ext1.'<extMap><extDate>'.$key.$value.'</extDate></extMap>'.$tr3Url.'</TxnMsgContent></MasMessage>';

//echo '$regXml: '.$reqXml.'<HR>';

$clientcert    ="/home/flightsharecar/user_upload/php_demo/cert.pem";
    $clientprikey="/home/flightsharecar/user_upload/php_demo/private.pem";

//$challenge      = "vpos123";
$tuCurl = curl_init();
$merchantId='812330945110001';//商户编号
$certPassword='vpos123';//证书密码
    $loginKey='vpos123';//商户登录密码
$loginInfo = array(
		"Authorization: Basic " . base64_encode($merchantId . ":" . $loginKey)
	);
curl_setopt($tuCurl, CURLOPT_URL, "https://sandbox.99bill.com:9445/cnp/purchase");
// Set your login and password for authentication
    /*
curl_setopt($tuCurl, CURLOPT_USERPWD, 'vpos123');
curl_setopt($tuCurl, CURLOPT_POST, 1);
curl_setopt($tuCurl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($tuCurl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($tuCurl, CURLOPT_HTTPHEADER, $loginInfo);
curl_setopt($tuCurl, CURLOPT_SSLCERT, $clientcert);
curl_setopt($tuCurl, CURLOPT_SSLCERTPASSWD, $challenge); 
curl_setopt($tuCurl, CURLOPT_SSLKEYTYPE, 'PEM');
curl_setopt($tuCurl, CURLOPT_POSTFIELDS, $reqXml);
curl_setopt($tuCurl, CURLOPT_RETURNTRANSFER, 1);
    */
    curl_setopt($tuCurl, CURLOPT_HTTPHEADER, $loginInfo);//请求头中包含merchantId和对应的密码的内容
    //curl_setopt($tuCurl, CURLOPT_USERPWD, $loginKey);//登录用户密码

    curl_setopt($tuCurl,CURLOPT_SSL_VERIFYPEER,false);
    curl_setopt($tuCurl,CURLOPT_SSL_VERIFYHOST,false);


    curl_setopt($tuCurl,CURLOPT_SSLCERTTYPE,'PEM');//证书格式
    curl_setopt($tuCurl,CURLOPT_SSLCERT,$clientcert);//证书路径
    curl_setopt($tuCurl,CURLOPT_SSLCERTPASSWD,$certPassword);//证书密码

    curl_setopt($tuCurl,CURLOPT_SSLKEYTYPE,'PEM');//本地私钥格式
    curl_setopt($tuCurl,CURLOPT_SSLKEY,$clientprikey);//私钥文件路径

    curl_setopt($tuCurl, CURLOPT_POST, 1);//POST
    curl_setopt($tuCurl, CURLOPT_POSTFIELDS, $reqXml);//POST内容中包含报文


    curl_setopt($tuCurl,CURLOPT_TIMEOUT,30);

    curl_setopt($tuCurl,CURLOPT_RETURNTRANSFER, 1);
    //curl_setopt($ch,CURLOPT_URL,$url);








$tuData=curl_exec($tuCurl);
    var_dump($tuData);

if(!curl_errno($tuCurl)){

$info = curl_getinfo($tuCurl);
  	
 // echo 'Took ' . $info['total_time'] . ' seconds to send a request to ' . $info['url'];
} else {

 echo 'Curl error: ' . curl_error($tuCurl);
}
echo '<HR><HR>';
echo '<h2>返回TR2通知信息</h2>';
eregi("<txntype>(.*)<\/txntype>", $tuData, $txntype);
eregi("<interactiveStatus>(.*)<\/interactiveStatus>", $tuData, $interactiveStatus);
eregi("<amount>(.*)<\/amount>", $tuData, $amount);
eregi("<merchantId>(.*)<\/merchantId>", $tuData, $merchantId);
eregi("<terminalId>(.*)<\/terminalId>", $tuData, $terminalId);
eregi("<entryTime>(.*)<\/entryTime>", $tuData, $entryTime);
eregi("<externalRefNumber>(.*)<\/externalRefNumber>", $tuData, $externalRefNumber);
eregi("<customerId>(.*)<\/customerId>", $tuData, $customerId);
eregi("<transTime>(.*)<\/transTime>", $tuData, $transTime);
eregi("<refNumber>(.*)<\/refNumber>", $tuData, $refNumber);
eregi("<responseCode>(.*)<\/responseCode>", $tuData, $responseCode);
eregi("<responseTextMessage>(.*)<\/responseTextMessage>", $tuData, $responseTextMessage);
eregi("<cardOrg>(.*)<\/cardOrg>", $tuData, $cardOrg);
eregi("<issuer>(.*)<\/issuer>", $tuData, $issuer);
eregi("<storableCardNo>(.*)<\/storableCardNo>", $tuData, $storableCardNo);

echo '<table align="center" bordercolor="green" border="1" style="border-collapse: collapse;width:610px">';
echo '<tr><td>交易类型(txntype)</td><td>'.$txntype[0].'</td></tr>';
echo '<tr><td>消息状态(interactiveStatus)</td><td>'.$interactiveStatus[0].'</td></tr>';
echo '<tr><td>金额(amount)</td><td>'.$amount[0].'</td></tr>';
echo '<tr><td><font color="#ff0000">商户号(merchantId)</font></td><td>'.$merchantId[0].'</td></tr>';
echo '<tr><td><font color="#ff0000">终端号(terminalId)</font></td><td>'.$terminalId[0].'</td></tr>';
echo '<tr><td>商户端交易时间(entryTime)</td><td>'.$entryTime[0].'</td></tr>';
echo '<tr><td><font color="#ff0000">外部跟踪编号(externalRefNumber)</font></td><td>'.$externalRefNumber[0].'</td></tr>';
echo '<tr><td>交易传输时间(transTime)</td><td>'.$transTime[0].'</td></tr>';
echo '<tr><td>系统参考号(refNumber)</td><td>'.$refNumber[0].'</td></tr>';
echo '<tr><td><font color="#ff0000">应答码(responseCode)</font></td><td>'.$responseCode[0].'</td></tr>';
echo '<tr><td><font color="#ff0000">应答码文本消息(responseTextMessage)</font></td><td>'.$responseTextMessage[0].'</td></tr>';
echo '<tr><td>卡组织编号(cardOrg)</td><td>'.$cardOrg[0].'</td></tr>';
echo '<tr><td>发卡银行名称(issuer)</td><td>'.$issuer[0].'</td></tr>';
echo '<tr><td>缩略卡号(storableCardNo)</td><td>'.$storableCardNo[0].'</td></tr>';

}
?>

</body>
</html>